home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2008 May / PersonalComputerWorld-May2008-CoverdiscCD.iso / Software / Full / Nero 7 / Installation / Cab / A97B5616.cab / MoveFocus97F004D4.js < prev    next >
Encoding:
JavaScript  |  2006-06-28  |  24.2 KB  |  618 lines

  1. // Variable to track where the focus is at any time. Its value will always be a focusable object on the page
  2.  
  3. var oCurFocus
  4.  
  5.  
  6.  
  7. // variable to track where the focus was previous to current focus.
  8.  
  9. var oPrevFocus = null
  10.  
  11.  
  12.  
  13. // variable to track which direction arrow was used to get between previous focus and current focus
  14.  
  15. var sPrevArrowDirection = null
  16.  
  17.  
  18.  
  19. // variable to trap first mouseover event
  20.  
  21. var bFirstMouseover = true
  22.  
  23.  
  24.  
  25. function startFocus()
  26.  
  27. // this function sets the initial focus on the page, plus it takes care of a few other tasks that are linked to the onload event
  28.  
  29. {
  30.  
  31.     // make sure that scrollbar does not appear at the side of the page
  32.  
  33.     // This is not integral to the rest of the function, but it's a convenient place to do it
  34.  
  35.      body.scroll="no"
  36.  
  37.  
  38.  
  39.     //Reset the variable that traps the first mouseover event on the page
  40.  
  41.     // This is not integral to the rest of the function, but it's a convenient place to do it
  42.  
  43.     // The MouseOver function in the Hilite.js file checks this variable to handle mouseover events
  44.  
  45.     // For more info, see comments in that file
  46.  
  47.     window.setTimeout("bFirstMouseover = false", 100)
  48.  
  49.  
  50.  
  51.     // check if media is playing and Shared viewport needs to be opened
  52.  
  53.     try
  54.  
  55.     {
  56.  
  57.         // call needViewport function, which checks if media is playing
  58.  
  59.         if (needViewport() == true)
  60.  
  61.         {
  62.  
  63.             window.external.MediaCenter.SharedViewPort.Visible = true
  64.  
  65.         }
  66.  
  67.     }
  68.  
  69.     catch(e)
  70.  
  71.     {
  72.  
  73.         // ignore error
  74.  
  75.     }
  76.  
  77.  
  78.  
  79.     /* if you are arriving at the page via the Back button, then focus should start on the same
  80.  
  81.     element it was on when you left. The browser will automatically focus on the correct element,
  82.  
  83.     but for the element to highlight correctly, you have to update a variable, move the focus to
  84.  
  85.     the BODY element, and then continue with the rest of this function. */
  86.  
  87.     // Check to see if initial focus is already on a focusable element
  88.  
  89.     if (document.activeElement.MCFocusable == "true")
  90.  
  91.     {
  92.  
  93.         // reset MCFocusStart variable, which instructs the page where to start the focus
  94.  
  95.         body.MCFocusStart = document.activeElement
  96.  
  97.         // move focus temporarily to BODY element, or focusable item will not highlight correctly
  98.  
  99.         body.focus()
  100.  
  101.     }
  102.  
  103.  
  104.  
  105.     // if oCurFocus does not already have a value, check the value for body.MCFocusStart
  106.  
  107.     if (oCurFocus == null)
  108.  
  109.     {
  110.  
  111.         try
  112.  
  113.         {
  114.  
  115.             oCurFocus = eval(body.MCFocusStart)
  116.  
  117.         }
  118.  
  119.         catch(e)
  120.  
  121.         {
  122.  
  123.             // if MCFocusStart is invalid, ignore error
  124.  
  125.         }
  126.  
  127.     }
  128.  
  129.  
  130.  
  131.     // if body.MCFocusStart has no value, and oCurFocus still has no value,
  132.  
  133.     // set oCurFocus to the first focusable item on the page. This will be the default state
  134.  
  135.     if (oCurFocus == null)
  136.  
  137.     {
  138.  
  139.         try
  140.  
  141.         {
  142.  
  143.             oCurFocus = aFocusableItemsArray[0]
  144.  
  145.             // make sure starting focus is not Shared Viewport
  146.  
  147.             if (oCurFocus.id == "SVP")
  148.  
  149.             {
  150.  
  151.                 oCurFocus = aFocusableItemsArray[1]
  152.  
  153.             }
  154.  
  155.         }
  156.  
  157.         catch(e)
  158.  
  159.         {
  160.  
  161.             //ignore error
  162.  
  163.         }
  164.  
  165.     }
  166.  
  167.  
  168.  
  169.     try
  170.  
  171.     {
  172.  
  173.         oCurFocus.focus()
  174.  
  175.     }
  176.  
  177.     catch(e)
  178.  
  179.     {
  180.  
  181.         //ignore error
  182.  
  183.     }
  184.  
  185. }
  186.  
  187.  
  188.  
  189.  
  190.  
  191. // array that will contain all focusable objects on the page
  192.  
  193. var aFocusableItemsArray = new Array()
  194.  
  195.  
  196.  
  197. function setArray()
  198.  
  199.  /* This function makes an array of all the focusable objects on the page and
  200.  
  201.  finds their exact locations on the page, making top and left properties for the center of each */
  202.  
  203. {
  204.  
  205.     // variable to track which focusable element we are dealing with
  206.  
  207.     var nextElement = 0
  208.  
  209.  
  210.  
  211.     // for all objects on the page ...
  212.  
  213.     for (i=0; i<body.all.length; i++)
  214.  
  215.     {
  216.  
  217.  
  218.  
  219.         //variable to identify object
  220.  
  221.         var obj = body.all(i)
  222.  
  223.         // If object is focusable ...
  224.  
  225.         if (obj.MCFocusable == "true")
  226.  
  227.         {
  228.  
  229.             // Set position, width, height, left and right as properties for the object
  230.  
  231.             var objPosition = obj.getBoundingClientRect();
  232.  
  233.             obj.nLeftPos = objPosition.left -2
  234.  
  235.             obj.nRightPos = objPosition.right -2
  236.  
  237.             obj.nTopPos = objPosition.top - 2
  238.  
  239.             obj.nBottomPos = objPosition.bottom -2
  240.  
  241.             obj.nWidth = (obj.nRightPos - obj.nLeftPos)
  242.  
  243.             obj.nHeight = (obj.nBottomPos - obj.nTopPos)
  244.  
  245.  
  246.  
  247.             //find top coordinate for center of item: Y position on page plus half of height
  248.  
  249.             var objCenterTop = (obj.nTopPos+(obj.nHeight/2))
  250.  
  251.             //find left coordinate for center of item: X position on page plus half of width
  252.  
  253.             var objCenterLeft = (obj.nLeftPos+(obj.nWidth/2))
  254.  
  255.             // assign top and left as custom property of object
  256.  
  257.             obj.nCenterYCoord = objCenterTop
  258.  
  259.             obj.nCenterXCoord = objCenterLeft
  260.  
  261.             // Place object in array of focusable items, in correct position
  262.  
  263.             aFocusableItemsArray[nextElement] = obj
  264.  
  265.             // update nextElement variable
  266.  
  267.             nextElement++
  268.  
  269.         }
  270.  
  271.  
  272.  
  273.         // check if object is a container for a "spinner"; if so, call function to show correct value
  274.  
  275.         if (obj.MCSpinnerContainer == "true")
  276.  
  277.         {
  278.  
  279.             try
  280.  
  281.             {
  282.  
  283.                 initializeSpinner(obj)
  284.  
  285.             }
  286.  
  287.             catch(e)
  288.  
  289.             {
  290.  
  291.              // if above function call is not valid, ignore error
  292.  
  293.              }
  294.  
  295.         }
  296.  
  297.     }
  298.  
  299. }
  300.  
  301.  
  302.  
  303. function checkForOppositeArrow(direction)
  304.  
  305. {
  306.  
  307.  
  308.  
  309.     /* this function checks if the arrow button pressed is in the opposite
  310.  
  311.     direction from the last arrow button pressed (e.g. up, then down, or left, then right) */
  312.  
  313.     // make sure that oPrevFocus and sPrevArrowDirection are not null
  314.  
  315.     if (oPrevFocus == null || sPrevArrowDirection == null) return false
  316.  
  317.     
  318.  
  319.     switch(direction)
  320.  
  321.     {
  322.  
  323.         case "up":
  324.  
  325.         {
  326.  
  327.             if  (sPrevArrowDirection == "down")
  328.  
  329.             {
  330.  
  331.                 return true;
  332.  
  333.             }
  334.  
  335.             break;
  336.  
  337.         }
  338.  
  339.         case "down":
  340.  
  341.         {
  342.  
  343.             if  (sPrevArrowDirection == "up")
  344.  
  345.             {
  346.  
  347.                 return true;
  348.  
  349.             }
  350.  
  351.             break;
  352.  
  353.         }
  354.  
  355.         case "left":
  356.  
  357.         {
  358.  
  359.             if  (sPrevArrowDirection == "right")
  360.  
  361.             {
  362.  
  363.                 return true;
  364.  
  365.             }
  366.  
  367.             break;
  368.  
  369.         }
  370.  
  371.         case "right":
  372.  
  373.         {
  374.  
  375.             if  (sPrevArrowDirection == "left")
  376.  
  377.             {
  378.  
  379.                 return true;
  380.  
  381.             }
  382.  
  383.             break;
  384.  
  385.         }
  386.  
  387.     }
  388.  
  389.     return false
  390.  
  391. }
  392.  
  393.  
  394.  
  395. function changeFocus(direction)
  396.  
  397. // this function moves the focus from one object to another based on input from the remote
  398.  
  399. {
  400.  
  401.     /* if the arrow button pressed is in the opposite
  402.  
  403.     direction from the last arrow button pressed (e.g. up, then down, or left, then right)
  404.  
  405.     move focus to the previous button, update variables, and end function */
  406.  
  407.     if (checkForOppositeArrow(direction) == true)
  408.  
  409.     {
  410.  
  411.         // remember oCurFocus value before changing it
  412.  
  413.         var oTemp = oCurFocus       
  414.  
  415.         // set focus back to previous focus button
  416.  
  417.         oCurFocus = oPrevFocus
  418.  
  419.         oCurFocus.focus()       
  420.  
  421.         // update oPrevFocus
  422.  
  423.         oPrevFocus = oTemp
  424.  
  425.         // update variable to track which direction arrow was pressed
  426.  
  427.         sPrevArrowDirection = direction
  428.  
  429.         // end function
  430.  
  431.         return      
  432.  
  433.     }
  434.  
  435.     
  436.  
  437.  
  438.  
  439.     
  440.  
  441.     // update variable to track where the focus was previous to current focus.
  442.  
  443.     oPrevFocus = oCurFocus
  444.  
  445.     // update variable to track which direction arrow was used to get between previous focus and current focus
  446.  
  447.     sPrevArrowDirection = direction
  448.  
  449.     
  450.  
  451.     
  452.  
  453.     // call function (below) to find nearest object to the one that has focus, in the direction of whatever arrow is pressed
  454.  
  455.     var nearestObj = findClosestItem(direction)
  456.  
  457.     
  458.  
  459.     // if nearestObj is null, then make sPrevArrowDirectio null
  460.  
  461.     if (nearestObj == null) sPrevArrowDirection = null
  462.  
  463.  
  464.  
  465.     // if focus is on the Shared Viewport and the user arrows in a direction that
  466.  
  467.     // has no other focusable items, put focus back on viewport
  468.  
  469.     if (oCurFocus.id == "SVP" && nearestObj == null)
  470.  
  471.     {
  472.  
  473.         window.external.MediaCenter.SharedViewPort.focus();
  474.  
  475.         return
  476.  
  477.     }
  478.  
  479.     if (oCurFocus.id == "CVP" && nearestObj == null)
  480.  
  481.     {
  482.  
  483.         window.external.MediaCenter.CustomViewPort.focus();
  484.  
  485.         return
  486.  
  487.     }
  488.  
  489.     // if there are no focusable objects in the direction indicated by arrow click, return
  490.  
  491.     if (nearestObj == null)
  492.  
  493.     {
  494.  
  495.         return
  496.  
  497.     }
  498.  
  499.     // set focus on new object
  500.  
  501.     oCurFocus = nearestObj
  502.  
  503.     oCurFocus.focus()
  504.  
  505.  
  506.  
  507.     // If focus is on shared viewport placeholder, move focus to real shared viewport
  508.  
  509.     if (oCurFocus.id == "SVP")
  510.  
  511.     {
  512.  
  513.         window.external.MediaCenter.SharedViewPort.focus();
  514.  
  515.         return
  516.  
  517.     }
  518.  
  519.  
  520.  
  521.     //If focus is on custom viewport placeholder, move focus to real custom viewport
  522.  
  523.     if (oCurFocus.id == "CVP")
  524.  
  525.     {
  526.  
  527.         window.external.MediaCenter.CustomViewPort.focus();
  528.  
  529.         return
  530.  
  531.     }
  532.  
  533.     try
  534.  
  535.     {
  536.  
  537.         // check if scrolling has taken place, using the didScroll function, and update positions of scrollable elements if needed
  538.  
  539.         if (didScroll())
  540.  
  541.         {
  542.  
  543.             bFirstMouseover = true;
  544.  
  545.             updateScrollPositions()
  546.  
  547.             window.setTimeout("bFirstMouseover = false", 100)
  548.  
  549.         }
  550.  
  551.     }
  552.  
  553.     catch(e)
  554.  
  555.     {
  556.  
  557.         // if didScroll function is not present, ignore error
  558.  
  559.     }
  560.  
  561. }
  562.  
  563.  
  564.  
  565.  
  566.  
  567. function findClosestItem(direction)
  568.  
  569. {
  570.  
  571. /* this function finds the the best item to navigate to based on which arrow key is pressed and on which item currently has the focus. To do this, it does up to three loops through all of the focusable items. On the first loop, it looks for items that are in a direct line in the direction selected, and finds the closest one. If the first loop finds no results, the second loop widens the search, looking for the closest item in the quadrant of the page (dividing the page like an X, not like a cross, with the current focus item at the center) in the direction selected. If there are no focusable items in the correct quadrant, the search widens a bit more, finding the closest item anywhere on the page (or, in effect, half of the page) in the direction selected. */
  572.  
  573.     //Variable for object that currently has focus
  574.  
  575.     var oOldObj = oCurFocus;
  576.  
  577.     // variable to track shortest item distance. Start with a high number (10,000) for value
  578.  
  579.     var nShortestItemDist = 10000
  580.  
  581.     // variable to track which object is nearest to the one that currently has focus
  582.  
  583.     var oNearestObj = null
  584.  
  585.  
  586.  
  587.     // first try to find any items that are exactly in the direction indicated; if any, return closest item
  588.  
  589.     for (i=0; i < aFocusableItemsArray.length; i++)
  590.  
  591.     {
  592.  
  593.  
  594.  
  595.         // Locate new object in array
  596.  
  597.         oNewObj = aFocusableItemsArray[i]
  598.  
  599.         // make sure object is not temporarily unfocusable
  600.  
  601.         if (oNewObj.MCTempUnFocusable == "true") continue
  602.  
  603.         // Make sure oNewObj is not oOldObj
  604.  
  605.         if (oOldObj == oNewObj)
  606.  
  607.         {
  608.  
  609.             continue
  610.  
  611.         }
  612.  
  613.  
  614.  
  615.         // call function to check if new object is in a straight line from old object, in direction indicated by selected arrow key;
  616.  
  617.         // if so, set nTempDist variable for distance
  618.  
  619.         var nTempDist = isInLine(oOldObj, oNewObj, direction)
  620.  
  621.  
  622.  
  623.         // if current object's distance is closest so far ...
  624.  
  625.         if (nTempDist != null && nTempDist < nShortestItemDist)
  626.  
  627.         {
  628.  
  629.             // update variable for shortest distance so far
  630.  
  631.             nShortestItemDist = nTempDist
  632.  
  633.             // update variable for closest object so far
  634.  
  635.             oNearestObj = oNewObj
  636.  
  637.         }
  638.  
  639.     }
  640.  
  641.     // if above process finds any objects in a straight line from old object, return the closest one.
  642.  
  643.     if (oNearestObj != null)
  644.  
  645.     {
  646.  
  647.         return oNearestObj
  648.  
  649.     }
  650.  
  651.  
  652.  
  653.     ////////////////////////////
  654.  
  655.     /* If no items exactly in correct direction, try to find any items that are in the correct quadrant
  656.  
  657.     for the direction indicated; if any, return closest item */
  658.  
  659.     for (i=0; i < aFocusableItemsArray.length; i++)
  660.  
  661.     {
  662.  
  663.         // Locate new object in array
  664.  
  665.         oNewObj = aFocusableItemsArray[i]
  666.  
  667.         // make sure object is not temporarily unfocusable
  668.  
  669.         if (oNewObj.MCTempUnFocusable == "true") continue
  670.  
  671.         // Make sure oNewObj is not oOldObj
  672.  
  673.         if (oOldObj == oNewObj) continue
  674.  
  675.  
  676.  
  677.         // call function to check if new object is in the correct quadrant from old object, in direction indicated by selected arrow key;
  678.  
  679.         // if so, set nTempDist variable for distance
  680.  
  681.         var nTempDist = isInQuadrant(oOldObj, oNewObj, direction)
  682.  
  683.  
  684.  
  685.         // if current object's distance is closest so far (of items in this loop) ...
  686.  
  687.         if (nTempDist != null && nTempDist < nShortestItemDist)
  688.  
  689.         {
  690.  
  691.             // update variable for shortest distance so far
  692.  
  693.             nShortestItemDist = nTempDist
  694.  
  695.             // update variable for closest object so far
  696.  
  697.             oNearestObj = oNewObj
  698.  
  699.         }
  700.  
  701.     }
  702.  
  703.     // if above process finds any objects in the correct quadrant from old object, return closest one
  704.  
  705.     if (oNearestObj != null)
  706.  
  707.     {
  708.  
  709.         return oNearestObj
  710.  
  711.     }
  712.  
  713.  
  714.  
  715.     /////////////////////////////////////
  716.  
  717.     /* If no items are in correct quadrant, try to find any items that are in the correct half of the page
  718.  
  719.     for the direction indicated; if any, return closest item */
  720.  
  721.     for (i=0; i < aFocusableItemsArray.length; i++)
  722.  
  723.     {
  724.  
  725.         // Locate new object in array
  726.  
  727.         oNewObj= aFocusableItemsArray[i]
  728.  
  729.         // make sure object is not temporarily unfocusable
  730.  
  731.         if (oNewObj.MCTempUnFocusable == "true") continue
  732.  
  733.         // Make sure nNewObj is not oOldObj
  734.  
  735.         if (oOldObj == oNewObj) continue
  736.  
  737.  
  738.  
  739.         // call function to check if new object is in the correct quadrant from old object, in direction indicated by selected arrow key;
  740.  
  741.         // if so, set nTempDist variable for distance
  742.  
  743.         var nTempDist = isInHalf(oOldObj, oNewObj, direction)
  744.  
  745.  
  746.  
  747.         // if current object's distance is closest so far (in this loop) ...
  748.  
  749.         if (nTempDist != null && nTempDist < nShortestItemDist)
  750.  
  751.         {
  752.  
  753.             // update variable for shortest distance so far
  754.  
  755.             nShortestItemDist = nTempDist
  756.  
  757.             // update variable for closest object so far
  758.  
  759.             oNearestObj = oNewObj
  760.  
  761.         }
  762.  
  763.     }
  764.  
  765.  
  766.  
  767.     // if above process finds any objects in the correct quadrant from old object, return closest object
  768.  
  769.     if (oNearestObj != null)
  770.  
  771.     {
  772.  
  773.         return oNearestObj
  774.  
  775.     }
  776.  
  777.     // If not, return null
  778.  
  779.     return null
  780.  
  781. }
  782.  
  783.  
  784.  
  785.  
  786.  
  787. function isInLine(oOldObj, oNewObj, direction)
  788.  
  789. {
  790.  
  791.     var nStraightDist = null
  792.  
  793.     // make sure object is not temporarily unfocusable
  794.  
  795.  
  796.  
  797.     if (direction == "down")
  798.  
  799.     {
  800.  
  801.         // if old object is above (less in y coordinate) new object, return null
  802.  
  803.         if (oOldObj.nCenterYCoord > oNewObj.nCenterYCoord)
  804.  
  805.         {
  806.  
  807.             return null
  808.  
  809.         }
  810.  
  811.         // if the current focus object's left edge is to the left of the new object's right edge, and the
  812.  
  813.         // current focus object's right edge is to the right of the new object's left edge ...
  814.  
  815.         if (oOldObj.nLeftPos < oNewObj.nRightPos && oNewObj.nLeftPos < oOldObj.nRightPos)
  816.  
  817.         {
  818.  
  819.             // then the new object and the old object overlap in the X coordinate
  820.  
  821.             // calculate distance based on (top of oNewObj - bottom of oOldObj)
  822.  
  823.             nStraightDist = (oNewObj.nTopPos - oOldObj.nBottomPos)
  824.  
  825.         }
  826.  
  827.         else
  828.  
  829.         {
  830.  
  831.             return null
  832.  
  833.         }
  834.  
  835.     }
  836.  
  837.     if (direction == "up")
  838.  
  839.     {
  840.  
  841.         // if old object is below (greater in y coordinate) new object, return null
  842.  
  843.         if (oOldObj.nCenterYCoord < oNewObj.nCenterYCoord)
  844.  
  845.         {
  846.  
  847.             return null
  848.  
  849.         }
  850.  
  851.         // if the current focus object's left edge is to the left of the new object's right edge, and the
  852.  
  853.         // current focus object's right edge is to the right of the new object's left edge ...
  854.  
  855.         if (oOldObj.nLeftPos < oNewObj.nRightPos && oNewObj.nLeftPos < oOldObj.nRightPos)
  856.  
  857.         {
  858.  
  859.             // then the new object and the old object overlap in the X coordinate
  860.  
  861.             // calculate distance based on (top of oOldObj - bottom of oNewObj)
  862.  
  863.             nStraightDist = (oOldObj.nTopPos - oNewObj.nBottomPos)
  864.  
  865.         }
  866.  
  867.         else
  868.  
  869.         {
  870.  
  871.             return null
  872.  
  873.         }
  874.  
  875.     }
  876.  
  877.     if (direction == "left")
  878.  
  879.     {
  880.  
  881.         // if old object is left of (less in x coordinate) new object, return null
  882.  
  883.         if (oOldObj.nCenterXCoord < oNewObj.nCenterXCoord)
  884.  
  885.         {
  886.  
  887.             return null
  888.  
  889.         }
  890.  
  891.         // if the current focus object's top edge is above of the new object's bottom edge,
  892.  
  893.         // and the current focus object's bottom edge is below the new object's top edge ...
  894.  
  895.         if (oOldObj.nTopPos < oNewObj.nBottomPos && oOldObj.nBottomPos > oNewObj.nTopPos)
  896.  
  897.         {
  898.  
  899.             // then the new object and the old object overlap in the Y coordinate
  900.  
  901.             // calculate distance based on (left edge of oOldObj - Right edge of oNewObj)
  902.  
  903.             nStraightDist = (oOldObj.nLeftPos - oNewObj.nRightPos)
  904.  
  905.         }
  906.  
  907.         else
  908.  
  909.         {
  910.  
  911.             return null
  912.  
  913.         }
  914.  
  915.     }
  916.  
  917.     if (direction == "right")
  918.  
  919.     {
  920.  
  921.         // if old object is right of (greater in x coordinate) new object, return null
  922.  
  923.         if (oOldObj.nCenterXCoord > oNewObj.nCenterXCoord)
  924.  
  925.         {
  926.  
  927.             return null
  928.  
  929.         }
  930.  
  931.         // if the current focus object's top edge is above of the new object's bottom edge,
  932.  
  933.         // and the current focus object's bottom edge is below the new object's top edge ...
  934.  
  935.         if (oOldObj.nTopPos < oNewObj.nBottomPos && oOldObj.nBottomPos > oNewObj.nTopPos)
  936.  
  937.         {
  938.  
  939.             // then the new object and the old object overlap in the Y coordinate
  940.  
  941.             // calculate distance based on (left edge of oNewObj - Right edge of oOldObj )
  942.  
  943.             nStraightDist = (oNewObj.nLeftPos - oOldObj.nRightPos)
  944.  
  945.         }
  946.  
  947.         else
  948.  
  949.         {
  950.  
  951.             return null
  952.  
  953.         }
  954.  
  955.     }
  956.  
  957.     return nStraightDist
  958.  
  959. }
  960.  
  961.  
  962.  
  963. function isInQuadrant(oOldObj, oNewObj, direction)
  964.  
  965. {
  966.  
  967.     // compare the difference between top and left for two objects to see what direction
  968.  
  969.     // the new object is in relative to the object that currently has focus.
  970.  
  971.     // Check distance between objects
  972.  
  973.     var xDif = Math.abs(oOldObj.nCenterXCoord - oNewObj.nCenterXCoord);
  974.  
  975.     var yDif = Math.abs(oOldObj.nCenterYCoord - oNewObj.nCenterYCoord);
  976.  
  977.  
  978.  
  979.     /* Determine quadrant (relative to the center of the current-focus object) that the new object falls in.
  980.  
  981.     Note that the term "quadrant" is used loosely here; the dividing lines between the quadrants form
  982.  
  983.     an X rather than a +. That way the arrow keys point to the center of each quadrant  */
  984.  
  985.     var quadrant
  986.  
  987.     if(xDif > yDif && oOldObj.nCenterXCoord > oNewObj.nCenterXCoord) quadrant = "left";
  988.  
  989.     if(xDif > yDif && oOldObj.nCenterXCoord <= oNewObj.nCenterXCoord) quadrant = "right";
  990.  
  991.     if(xDif <= yDif && oOldObj.nCenterYCoord > oNewObj.nCenterYCoord) quadrant = "up";
  992.  
  993.     if(xDif <= yDif && oOldObj.nCenterYCoord <= oNewObj.nCenterYCoord) quadrant = "down";
  994.  
  995.  
  996.  
  997.     // make sure object is in correct quadrant ...
  998.  
  999.     if (quadrant != direction) return null
  1000.  
  1001.  
  1002.  
  1003.     // Find distance between centers of objects; (project a right triangle and calculate hypotenuse)
  1004.  
  1005.     var nQuadDist = Math.sqrt((xDif * xDif) + (yDif * yDif))
  1006.  
  1007.     return nQuadDist
  1008.  
  1009. }
  1010.  
  1011.  
  1012.  
  1013. function isInHalf(oOldObj, oNewObj, direction)
  1014.  
  1015. /* if checkItemDist function cannot find any focusable items in the correct quadrant, this function
  1016.  
  1017. widens the search a bit. Instead of using quadrants, it considers focusable items that lie at least 41 pixels away
  1018.  
  1019. in the direction (up, down, left or right) indicated by the arrow key. Example: if the user hits the right arrow key,
  1020.  
  1021. this function will consider any focusable item whose X coordinate is at least 41 pixels greater than that of the
  1022.  
  1023. current-focus item, no matter what its Y coordiant is. From among those, it then calculates which is closest.        */
  1024.  
  1025. {
  1026.  
  1027.     // variable for distance between old and new objects
  1028.  
  1029.     var nHalfDist
  1030.  
  1031.  
  1032.  
  1033.         var bIsInCorrectArea = false
  1034.  
  1035.         // determine whether new item lies at least 41 pixels into the half of the page (relative to the current-focus item)
  1036.  
  1037.         // that matches the arrow key pressed (example: if right arrowkey pressed, new item must
  1038.  
  1039.         // have an X coodrinate that is at least 41 px greater than that of the current-focus item, or bIsInCorrectArea
  1040.  
  1041.         // will not be set to true)
  1042.  
  1043.         if (direction == "up" && (oOldObj.nCenterYCoord - 40) > oNewObj.nCenterYCoord)
  1044.  
  1045.         {
  1046.  
  1047.             bIsInCorrectArea = true
  1048.  
  1049.         }
  1050.  
  1051.         if (direction == "down" && (oOldObj.nCenterYCoord + 40) < oNewObj.nCenterYCoord)
  1052.  
  1053.         {
  1054.  
  1055.             bIsInCorrectArea = true
  1056.  
  1057.         }
  1058.  
  1059.         if (direction == "left" && (oOldObj.nCenterXCoord - 40) > oNewObj.nCenterXCoord)
  1060.  
  1061.         {
  1062.  
  1063.             bIsInCorrectArea = true
  1064.  
  1065.         }
  1066.  
  1067.         if (direction == "right" && (oOldObj.nCenterXCoord + 40) < oNewObj.nCenterXCoord)
  1068.  
  1069.         {
  1070.  
  1071.             bIsInCorrectArea = true
  1072.  
  1073.         }
  1074.  
  1075.  
  1076.  
  1077.         // If object is not in correct area, end function
  1078.  
  1079.         if (bIsInCorrectArea == false) return null
  1080.  
  1081.  
  1082.  
  1083.         // Compare the difference between top and left for two objects to see what direction
  1084.  
  1085.         // the second object is in relative to the first.
  1086.  
  1087.         // Check distance between objects
  1088.  
  1089.         var xDif = Math.abs(oOldObj.nCenterXCoord - oNewObj.nCenterXCoord);
  1090.  
  1091.         var yDif = Math.abs(oOldObj.nCenterYCoord - oNewObj.nCenterYCoord);
  1092.  
  1093.  
  1094.  
  1095.         // Find distance between centers of objects; (project a right triangle and calculate hypotenuse)
  1096.  
  1097.         var nHalfDist = Math.sqrt((xDif * xDif) + (yDif * yDif))
  1098.  
  1099.     return (nHalfDist)
  1100.  
  1101. }
  1102.  
  1103.  
  1104.  
  1105.  
  1106.  
  1107.  
  1108.  
  1109.  
  1110.  
  1111. function checkSVP()
  1112.  
  1113. // this function makes the Shared Viewport focusable. To make it work, you must place a span (or div, or whatever)
  1114.  
  1115. // in the lower left corner of the page to act as a placeholder for the actual Viewport; its ID must be "SVP"
  1116.  
  1117. {
  1118.  
  1119.     // make it so you can focus on the SVP placeholder span only if the real SVP is visible
  1120.  
  1121.     try
  1122.  
  1123.     {
  1124.  
  1125.         if (window.external.MediaCenter.SharedViewPort.Visible == true)
  1126.  
  1127.          {
  1128.  
  1129.             /* MCTempUnFocusable is a custom property with which you can make an item temporarily non-focusable, without
  1130.  
  1131.                 having to remove it from the aFocusableItemsArray. Set it to "false" */
  1132.  
  1133.             SVP.MCTempUnFocusable="false"
  1134.  
  1135.         }
  1136.  
  1137.         else
  1138.  
  1139.         {
  1140.  
  1141.             // If the Shared Viewport is hidden, maks its stand-in non-focusable
  1142.  
  1143.             SVP.MCTempUnFocusable="true"
  1144.  
  1145.         }
  1146.  
  1147.     }
  1148.  
  1149.     catch(e)
  1150.  
  1151.     {
  1152.  
  1153.         // If above gets error, probably not using Media Center, so just make placeholder unfocusable
  1154.  
  1155.         try
  1156.  
  1157.         {
  1158.  
  1159.             SVP.MCTempUnFocusable="true"
  1160.  
  1161.         }
  1162.  
  1163.         catch(e)
  1164.  
  1165.         {
  1166.  
  1167.             // if no object with id of "SVP" exists, ignore error
  1168.  
  1169.         }
  1170.  
  1171.     }
  1172.  
  1173. }
  1174.  
  1175.  
  1176.  
  1177. function checkCVP()
  1178.  
  1179. // If you are using a Custom Viewport this function makes it focusable.
  1180.  
  1181. // To make it work, you must have a span (or div, or whatever) on your page to act as a placeholder.
  1182.  
  1183. //Its ID must be "CVP" and it should be in the same position and size as your custom viewport
  1184.  
  1185. {
  1186.  
  1187.     // make it so you can focus on the CVP placeholder span only if the real CVP is visible
  1188.  
  1189.     try
  1190.  
  1191.     {
  1192.  
  1193.         if (window.external.MediaCenter.CustomViewPort.Visible == true)
  1194.  
  1195.          {
  1196.  
  1197.             CVP.MCTempUnFocusable="false"
  1198.  
  1199.         }
  1200.  
  1201.         else
  1202.  
  1203.         {
  1204.  
  1205.             CVP.MCTempUnFocusable="true"
  1206.  
  1207.         }
  1208.  
  1209.     }
  1210.  
  1211.     catch(e)
  1212.  
  1213.     {
  1214.  
  1215.         // If above gets error, probably not using Media Center, so just make placeholder unfocusable
  1216.  
  1217.         try
  1218.  
  1219.         {
  1220.  
  1221.             CVP.MCTempUnFocusable="true"
  1222.  
  1223.         }
  1224.  
  1225.         catch(e)
  1226.  
  1227.         {
  1228.  
  1229.             // if no object with id of "CVP" exists, ignore error
  1230.  
  1231.         }
  1232.  
  1233.     }
  1234.  
  1235. }